package com.jia.leetCode;

import java.util.Arrays;
import java.util.OptionalInt;

/**
 * @program: Leetcode
 * @description:
 * @author: STU756
 * @create: 2020-08-21 18:01
 */
public class Pro0264 {
    public int nthUglyNumber(int n) {
        int[] dp = new int[n];
        dp[0] = 1;
        int i = 0, j = 0, k = 0;
        for(int a = 1; a < n;a++) {
            dp[a] = Arrays.stream(new int[]{dp[i] * 2, dp[j] * 3, dp[k] * 5}).min().getAsInt();
            if(dp[i]*2 == dp[a]) {++i;}
            if(dp[j]*3 == dp[a]) {++j;}
            if(dp[k]*5 == dp[a]) {++k;}
        }
        return dp[n-1];
    }
}
